#pragma once
#include "gtest\gtest.h"
#include <iostream>
using namespace std;
class list_node
{
public:
	list_node(int val): _next(0), _prev(0), _val(val)
	{
	}
	list_node* _next;
	list_node* _prev;
	      int  _val;
};
class algo_list
{
public:
	algo_list(int val = 0): _head(new list_node(val)), _tail(_head)
	{
	}
	~algo_list()
	{
		list_node* cur = _head;
		while( !cur ) 
		{
			list_node* next = cur->_next;
			delete cur;
			cur = next;
		}
	}
	list_node* push_back(int val)
	{
		_tail->_next = new list_node(val);
		_tail->_next->_prev = _tail;
		_tail = _tail->_next;
		return _tail;
	}

	list_node* get_head()
	{
		return _head;
	
	}
	
	void reverse()
	{
		list_node* cur = _head;
		//list_node* prev = 0;
		list_node* next = 0;
		while( cur != 0 )
		{
			next = cur->_next;
			//prev = cur->_prev;
			cur->_next = cur->_prev;
			cur->_prev = next;
			cur = next;
		}

		std::swap(_tail, _head);
		//list_node* tmp = _tail;
		//_tail = _head;
		//_head = tmp;
	}

	void reserve_single()
	{
		list_node* cur = _head->_next;
		list_node* prev = _head;
		_head->_next = 0;
		list_node* next = 0;
		while( cur != 0 )
		{
			next = cur->_next;
			cur->_next = prev;
			prev = cur;
			cur = next;
		}

		_head = prev;
	}
private:
	list_node* _head;
	list_node* _tail;
};

ostream& operator<<(ostream& stream, algo_list list);

class listTest : public ::testing::Test
{
public:
	listTest(void);
	~listTest(void);
protected:
	virtual void SetUp()
	{
		int a[] = {1,2,3,4,5,6,7,8,9};
		for(int i=0; i < 9; ++i)
		{
			_list.push_back(a[i]);
		}

	}

	algo_list  _list;
};

